home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / COMMS / C011.ZIP / LUMP.C < prev    next >
Text File  |  1990-01-19  |  2KB  |  65 lines

  1.  
  2. /********************************************************************
  3.  * C Users Group (U.K) C Source Code Library File CUGLIB.011        *
  4.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  5.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  6.  ********************************************************************
  7.  * File name: lump.c
  8.  * Program name: lump
  9.  * Source of file: The Public Domain Software Library.
  10.  * Purpose: lump together a group of files. (Use UNLUMP to break apart)
  11.  * Changes: <who what when & why major changes have been made>  
  12.  ********************************************************************/
  13.  
  14. #include "stdio.h"
  15.  
  16. FILE *infile, *outfile;
  17.  
  18. main(argc,argv)
  19. int argc;
  20. char *argv[];
  21. {
  22.    int c, i;
  23.  
  24.    if(argc<3)  { usage(); exit(0); }
  25.  
  26.    argc--;
  27.    if( exists(argv[1]) )    { usage(); exit(1);  }
  28.    if( (outfile=fopen(argv[1], "w")) == NULL )    { usage();  exit(1); }
  29.    for( i=2; i<=argc; i++ ) {
  30.       if( (infile=fopen(argv[i],"r")) == NULL )  { inerr(argv[i]); exit(2); }
  31.       fprintf(outfile, "*FILE: %s\n", argv[i]);
  32.       printf("*FILE: %s\n", argv[i]);
  33.       while ( (c=getc(infile)) >= 0)
  34.          putc(c,outfile);
  35.       fclose(infile);
  36.    }
  37.  
  38. }
  39.  
  40.  
  41. usage()
  42. {
  43.    printf("Usage:  lump outfile infile1 ... \n");
  44.    printf("   Lump all input files into the output file,\n");
  45.    printf("   each being preceeded with a line identifying itself:\n");
  46.    printf("      *FILE: filename.ext\n\n");
  47. }
  48.  
  49.  
  50. inerr(s)
  51. char *s;
  52. {
  53.    printf("\nError opening file %s\n", s);
  54. }
  55.  
  56.  
  57. exists(s)
  58. char *s;
  59. {
  60.    FILE *f;
  61.    if( (f=fopen(s,"r")) == NULL )  return 0;
  62.    fclose(f);
  63.    return 1;
  64. }
  65.